package com.bayair.doctor.ui.main;

import com.bayair.doctor.data.bean.Token;
import com.bayair.doctor.mvp.BasePresenter;
import com.bayair.doctor.mvp.annotation.InjectModel;
import com.bayair.doctor.net.RxFunction;
import com.bayair.doctor.net.RxSchedulers;
import com.bayair.doctor.biz.helper.SpDoctor;



public class MainPresenter extends BasePresenter<MainContract.View> implements MainContract.Presenter {

    @InjectModel
    MainModel mModel;

    @Override
    public void flushToken() {
        getView().showLoadToken();
        mModel.flushToken()
                .map(new RxFunction<>())
                .compose(RxSchedulers.io_main())
                .doFinally(() -> getView().complete())
                .subscribe(new ObserverOnRecycler<Token>() {
                    @Override
                    public void onNext(Token token) {
                        String newtoken = token.getNewtoken();
                        SpDoctor.setToken(newtoken);

                    }
                });
    }

}
